<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>帖子仓库</title>
    <link rel="stylesheet" href="${base}/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${base}/css/admin.css">
    <style>
    	.layui-bg-black{width: 200px;height: 136px;margin-right: 30px;float: left;text-align: center;font-size: 33px;color: #000000!important;padding-top: 30px;}
    	.hide {display: none;}
    	.checkbox{display: inline-block;}
    	.layui-form-item{font-size: 18px;}
    	.width100 {width: 100px; margin-right: 30px;float: left;}
    	.width180 {width: 180px; margin-right: 20px;float: left;}
    	.layui-input { display: inline-block; }
    	
    </style>
</head>
<body  class="layui-layout-body" style="overflow:scroll;">
<#include "/common/left.flt">	
<div class="layui-main" style="position: absolute;left: 204px;top: 4px; width: calc(100% - 210px);" >
<fieldset class="layui-elem-field layui-field-title" >
  <legend>操作提示</legend>
</fieldset>
<div class="layui-form hide" id="card" style="padding-top:20px;padding-right:20px;">
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">内容</label>
    <div class="layui-input-block">
      <textarea name="content" id="content" class="layui-textarea" ></textarea>
    </div>
   </div>
   <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">图片</label>
    <div class="layui-input-block">
    	<button type="button" class="layui-btn" id="upload" ><i class="fa fa-upload" ></i></button>
    </div>
   </div>
</div>

<blockquote class="layui-elem-quote layui-quote-nm">
 	<form action="${base}/card_list/house" method="post" id="dataForm" >
        <input type="hidden" id="page" name="page" value="1"/>
        <input type="hidden" id="sex" name="sex" value="1"/>
 		<div class="layui-input-inline" style="margin-top: 10px;">
 			<input placeholder="帖子id" name ="card_id" class="width180 layui-input" value="${card_id?default('')}" />
 			<input placeholder="五十度id" name ="user_id" class="width180 layui-input" value="${user_id?default('')}" />
 			<input placeholder="手机号" name ="user_mobile" class="width180 layui-input" value="${user_mobile?default('')}" />
 			<input placeholder="昵称" name ="nick_name" class="width180 layui-input" value="${nick_name?default('')}" />
 			<input placeholder="内容" name ="content" class="width180 layui-input" value="${content?default('')}" />
 			<div class="layui-form" style="display: inline-block;">
		 		<div class="layui-input-inline layui-form-item" >
		 			<label class="layui-form-label"></label>
				    <div class="layui-input-block">
				    	<a class="layui-btn" id="btn_card" > <span class="fa  fa-linux"></span>新加</a>
				      <button class="layui-btn" lay-submit=""> <span class="fa fa-search"></span>查询</button>
				    </div>
		 		</div>
	 		</div>
 		</div>
 		
    </form>
 	
</blockquote> 

<table class="layui-table" >
	<thead>
       <tr>
           <th><input type="checkbox" id="all" />帖子</th>
<!--            <th>圈子</th> -->
           <th>用户</th>
           <th>昵称</th>
           <th>sex</th>
           <th>省份</th>
           <th width="160px">内容</th>
<!--            <th>类型</th> -->
           <th>推荐</th>
           <th>展示</th>
	 	   <th>审核</th>
           <th>置顶</th>
           <th>评论/浏览/热度</th>
           <th >操作</th>
        </tr>
     </thead>
     <tbody>
     <#list page.list as one>
     <tr>
     	<td ><input type="checkbox" name="id" value="${one.id}" /><a href="${base}/card_list/detail?id=${one.id}" target="_blank">${one.id}</a></td>
<!--      	<td>${one.social_title?default('')}</td> -->
     	<td title="用户手机:${one.user_mobile?default('')}"><a href="${base}/users_list/detail?user_id=${one.user_id}" target="_blank" >${one.user_id?default('')}</a></td>
     	<td><script>document.write(decodeURIComponent("${one.nick_name}"));</script></td>
     	<td>${one.sex_name?default('')}</td>
     	<td>${one.area_name?default('')}</td>
     	<td title="${one.content}"><#if one.content?length gt 10>${one.content?substring(0,10)}...<#else>${one.content}</#if></td>
<!--      	<td>${one.card_type_name}</td> -->
     	<td><a onclick="alt(${one.id});" > <#if one.alt_tj == 1><span class="fa fa-times-circle"></span><#else><span class="fa fa-check-circle"></span></#if></a></td>
     	<td><a onclick="show(${one.id});"><#if one.is_show == 1><span class="fa fa-check-circle"></span><#else><span class="fa fa-times-circle"></span></#if></a></td>
		<td><a onclick="_check(${one.id});"><#if one.is_check == 1><span class="fa fa-check-circle"></span><#else><span class="fa fa-times-circle"></span></#if></a></td>
     	<td><a onclick="_top(${one.id});"><#if one.is_top == 1><span class="fa fa-times-circle"></span><#else><span class="fa fa-check-circle"></span></#if></a></td>
     	<td>${one.discuss_cnt?default('0')}/${one.views?default('0')}/${one.heat?default('0')}</td>
     	<td><a onclick="del(${one.id});" ><span class="fa fa-trash"></span></a> <a onclick="zan(${one.id});" ><span class="fa fa-thumbs-o-up"></span></a>
     	<a onclick="follow(${one.id});" title="关注" ><span class="fa fa-eye"></span></a>
     	<#if base=="/50du"><a onclick="copy(${one.id});" title="复制" ><span class="fa fa-copy"></span></a></#if>
     	</td>
     </tr>
     </#list>
     </tbody>
</table>
<div id="pageDiv"></div>
<form action="${base}/util/uploadFile" method="post" name="uploadForm" enctype="multipart/form-data" id="uploadForm" class="hide" >
    <input name="pic" type="file" id="pic" class="hide"/>
</form>
</body>
<script src="${base}/js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="${base}/js/jquery.form.js"></script>
<script src="${base}/layui/layui.all.js"></script>

<script type="text/javascript">
$("#social").val('${social?default('')}');
$("#area").val('${area?default('')}');
$("#sex").val('${sex?default('')}');

layui.use('laypage',function () {
    var laypage = layui.laypage ;
    laypage.render({
        elem:"pageDiv",
        count:${page.totalPage*15},
        limit:15,
        curr:${page.pageNumber},
        layout:['count','prev','page','next','skip'],
        jump:function (obj,first) {
            var page = obj.curr;
            if(!first){
                $("#page").val(page);
                $("#dataForm").submit();
            }
        }
    });
});

function zan(id){
	layer.prompt({title: '请输入点赞数量，并确认', formType: 2}, function(content, index){
		$.post("${base}/card_list/giveLike",
		   		{"id":id,"num":content},function(data){ 
		   			layer.alert(data);
		   		}
		    );
		layer.close(index);
    });	
}
function follow(id){
	layer.prompt({title: '请输入关注数量，并确认', formType: 2}, function(content, index){
		$.post("${base}/card_list/giveFollow",
		   		{"id":id,"num":content},function(data){ 
		   			layer.alert(data);
		   		}
		    );
		layer.close(index);
    });	
}



var _id = 0 ;
$('body').bind('keyup', function(event) {
	　　if (event.keyCode == "13") {
	　　　　//回车执行查询
	　　　　_del();
	　　}
});
	
function _del(){
	console.log("_del " + _id);
	if (_id > 0 ){
		$.post("${base}/card_list/del",
		   		{"id":_id},function(data){ 
		   			layer.alert(data);
		   			window.location.reload();
		   		}
		    );
	}
}
	
function del(id){
	_id = id;
	//询问框
	layer.confirm('确定要删除吗？', {
	  btn: ['确定'] //按钮
	}, function(){
		_del();
	});
}

function alt(id){
	$.post("${base}/card_list/alt",
	   		{"id":id},function(data){ 
	   			layer.alert(data);
	   			window.location.reload();
	   		}
	    );  
}

function show(id){
	$.post("${base}/card_list/show",
	   		{"id":id},function(data){ 
	   			layer.alert(data);
	   			window.location.reload();
	   		}
	    );  
}

function _check(id){
	$.post("${base}/card_list/check",
	   		{"id":id},function(data){ 
	   			layer.alert(data);
	   			window.location.reload();
	   		}
	    );  
}

function _top(id){
	$.post("${base}/card_list/top",
	   		{"id":id},function(data){ 
	   			layer.alert(data);
	   			window.location.reload();
	   		}
	    );  
}

function copy(id){
	$.post("${base}/card_list/copy",
	   		{"card_id":id},function(data){ 
	   			layer.alert(data);
	   			window.location.reload();
	   		}
	    );  
}


$("#all").click(function (){
	if ($("#all").prop("checked")) {
		$("input[name='id']").prop("checked", true);
	} else {
		$("input[name='id']").prop("checked", false);
	}
});

$("#zan_x").click(function (){
	 try {
		var ids = "";
		$('input[name="id"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
			ids = ids + $(this).attr("value")+",";
	    });
		if(ids){
			$.post("${base}/card_list/give_like_select",
			   		{"ids":ids},function(data){ 
			   			layer.msg(data);
			   		}
			    );
		}
     }catch(e) {
        console.log(e)
     }
});
$("#views_x").click(function (){
	 try {
		var ids = "";
		$('input[name="id"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
			ids = ids + $(this).attr("value")+",";
	    });
		if(ids){
			$.post("${base}/card_list/give_views_select",
			   		{"ids":ids},function(data){ 
			   			layer.msg(data);
			   		}
			    );
		}
    }catch(e) {
       console.log(e)
    }
});

$("#hot_x").click(function (){
	 try {
		var ids = "";
		$('input[name="id"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
			ids = ids + $(this).attr("value")+",";
	    });
		if(ids){
			$.post("${base}/card_list/give_hot_select",
			   		{"ids":ids},function(data){ 
			   			layer.msg(data);
			   		}
			    );
		}
    }catch(e) {
       console.log(e)
    }
});

$("#hot_x_2").click(function (){
	 try {
		var ids = "";
		$('input[name="id"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
			ids = ids + $(this).attr("value")+",";
	    });
		if(ids){
			$.post("${base}/card_list/give_hot_select_2",
			   		{"ids":ids},function(data){ 
			   			layer.msg(data);
			   		}
			    );
		}
   }catch(e) {
      console.log(e)
   }
});


var images = "";
$("#btn_card").click(function (){
	layui.use('form', function() {
	    var form = layui.form;
	    form.render('select');
	});
	layer.open({
	    type: 1 ,
	    title: '发帖子',   //标题
	    area: ['600px', '400px'],   //宽高
	    shade: 0.4,   //遮罩透明度
	    content: $("#card"),
	    btn: ['确定'], //按钮组
	    scrollbar: false ,//屏蔽浏览器滚动条
	    yes: function(index){
	    	var content = $("#content").val();
	    	if (content){
	    		$.post("${base}/card_list/quick_insert",
				   		{"images":images,"content":content},function(data){ 
				   			layer.msg(data);
				   			$("#content").val("");
				   		    images = "";
				   		    $("img.data").remove();
				   			//$("#card").hide();
				   		}
				 );	
	    	}
	        layer.close(index);
	        
	        $("#card").hide();
	    },
		cancel: function(){
			$("#card").hide();        
	    }
	});
});
	
var currentPic = null;

$('body').on('click', '#upload', function () {
    currentPic = $(this);
    $("#pic").attr("accept","image/*");
    $("#pic").click();
});
$("#pic").change(function (){
    var fileName = $("#pic").val()
    var options = {
        success:  showResponse,  //处理完成的回调函数
        resetForm: true,
        //dataType:  'json'
    };
    $("#uploadForm").ajaxSubmit(options);
});

function showResponse(data)  {
    console.log(data);
    if(data.error == 0) {
    	currentPic.before("<img class=\"data\" src=\"http://qiniu.static.50dufei.top\/"+data.url+"?imageView2/1/w/100/h/100\" />") 
    	images  = images + data.url + ","; 
    } else {
    	layer.alert(data.message);
    }
}
</script>
</html>